<@app.html>
    <@app.head>
    <script>
        $(function () {
            $('#page_table').datagrid({
                fit: true,
                striped: true,
                pagination: true,
                url: "${contextPath}/security/hdw/battery/page.htm?healthy=${healthy}",  <#--url:一个用以从远程站点请求数据的超链接地址。-->
                fitColumns: true,
                pageSize: 10,
                pageList: [10, 50, 100],
                idField: 'id',
                singleSelect: true,
                selectOnCheck: false,
                checkOnSelect: false,
                autoRowHeight: false,
                rowStyler: gridRowStyler,
                columns: [
                    [
                        {
                            title: '电池序号',
                            align: 'center',
                            field: 'batteryId',
                            width: 50,
                            formatter: function (val, row) {
                                return row.id;
                            }
                        },
                        {
                            title: '外壳编号',
                            align: 'center',
                            field: 'shellCode',
                            width: 70
                        },
                        {
                            title: '对应订单',
                            align: 'center',
                            field: 'orderId',
                            width: 60
                        },
                       /* {
                            title: '厂商',
                            align: 'center',
                            field: 'supplierName',
                            width: 60
                        },*/
                       /* {
                            title: '电池组序号',
                            align: 'center',
                            field: 'packNo',
                            width: 50
                        },*/
                        {
                            title: '对应终端',
                            align: 'center',
                            field: 'lastCabinetId',
                            width: 40
                        },
                        {
                            title: '当前电量',
                            align: 'center',
                            field: 'socVolume',
                            width: 25,
                            formatter: function (val, row) {
                                if(val == null) {
                                    return '';
                                }
                                if (val < 10) {
                                    return '<p style="color:red">' + val + '%</p>';
                                }
                                return val+"%";
                            }
                        },
                        {
                            title: '健康度',
                            align: 'center',
                            field: 'healthy',
                            width: 25,
                            formatter: function (val) {
                                if (val == null) {
                                    return '';
                                }
                                if (val < 80) {
                                    return '<p style="color:red">' + val + '</p>';
                                }
                                return val;
                            }
                        },
                        {
                            title: '温度(℃)',
                            align: 'center',
                            field: 'temp',
                            width: 20,
                            formatter: function (val) {
                                if (val == null) {
                                    return '';
                                }
                                if (val > 65 || val < -40) {
                                    return '<p style="color:red">' + val + '</p>';
                                }
                                return val;
                            }
                        },
                        {
                            title: '电压(V)',
                            align: 'center',
                            field: 'voltage',
                            width: 25,
                            formatter: function (val, row) {
                                if(val == null || val == 0){
                                    return Number(0).toFixed(2);
                                }
                                return Number(val / 100).toFixed(2);
                            }
                        },
                        {
                            title: '电流(A)',
                            align: 'center',
                            field: 'electricity',
                            width: 25,
                            formatter: function (val, row) {
                                if(val == null || val == 0){
                                    return Number(0).toFixed(2);
                                }
                                if (val > 2500) {
                                    var ele = Number(val / 100).toFixed(2);
                                    return '<p style="color:red">' + ele + '</p>';
                                }
                                return Number(val / 100).toFixed(2);
                            }
                        },
                        {
                            title: '状态',
                            align: 'center',
                            field: 'statusName',
                            width: 20
                        },
                        /*{
                            title: '充电阶段',
                            align: 'center',
                            field: 'chargeStage',
                            width: 25,
                            formatter: function (val, row) {
                                switch (val) {
                                    case 4:
                                        return '已充满';
                                    default:
                                        return '未充满';
                                }
                            }
                        },*/
                        /*{
                            title: '使用次数',
                            align: 'center',
                            field: 'exchangeAmount',
                            width: 25
                        },*/
                        /*{
                            title: '刷新时间',
                            align: 'center',
                            field: 'refreshTime',
                            width: 60
                        },*/
                        {
                            title: '操作',
                            align: 'center',
                            field: 'id',
                            formatter: function (val, row) {
                                var html = '<a href="javascript:view(\'ID\')">查看</a>';
                                <@app.has_oper oper_code='3_3_3'>
                                    html += ' <a href="javascript:edit(\'ID\')">修改</a>';
                                </@app.has_oper>
                                <@app.has_oper oper_code='3_3_4'>
                                    html += ' <a href="javascript:remove(\'ID\')">删除</a>';
                                </@app.has_oper>
                                <@app.has_oper oper_code='3_3_6'>
                                    html += ' <a href="javascript:battery_location(\'ID\')">轨迹</a>'
                                </@app.has_oper>
                                <@app.has_oper oper_code='3_3_7'>
                                    html += ' <a href="javascript:usageLogNew(\'ID\')">使用记录</a>';
                                </@app.has_oper>
                                <@app.has_oper oper_code='3_3_8'>
                                    html += ' <a href="javascript:battery_log(\'ID\')">日志</a>';
                                </@app.has_oper>
                                return html.replace(/ID/g, row.id);
                            }
                        }
                    ]
                ],
                onLoadSuccess: function () {
                    $('#page_table').datagrid('clearChecked');
                    $('#page_table').datagrid('clearSelections');
                }
            });
        });
        function reload() {
            var datagrid = $('#page_table');
            datagrid.datagrid('reload');
        }

        function query() {
            $('#page_table').datagrid('options').queryParams = {
                id: $('#batteryId').val(),
                shellCode: $('#shellCode').val(),
                supplierId: $('input[name="supplierId"]').val(),
                status: $('input[name="status"]').val(),
                agentId:$('input[name="agentId"]').val(),
                agencyId:$('input[name="agencyId"]').val()
            };
            $('#page_table').datagrid('load');
        }

        function add() {
            App.dialog.show({
                css: 'width:300px;height:320px;',
                title: '新建',
                href: "${contextPath}/security/hdw/battery/add.htm",
                event: {
                    onClose: function () {
                        reload();
                    }
                }
            });
        }
        function faultBatteryClick() {
            var datagrid = $('#page_table');
            datagrid.datagrid('load',{
                healthyFlag: 1
            });
        }
        function abnormalBatteryClick() {
            var datagrid = $('#page_table');
            datagrid.datagrid('load',{
                healthyFlag: 2
            });
        }
        <#-- 电池轨迹 -->
        function battery_location(id) {
            App.dialog.show({
                css: 'width:1200px;height:760px;',
                title: '电池轨迹',
                href: "${contextPath}/security/hdw/battery/battery_location.htm?id=" + id,
                event: {}
            });
        }

        function remove(id) {
            $.messager.confirm('提示信息', '确认删除?', function (ok) {
                if (ok) {
                    $.post("${contextPath}/security/hdw/battery/delete.htm?id=" + id, function (json) {
                        if (json.success == 1) {
                            $.messager.alert('提示消息', '操作成功', 'info');
                            reload();
                        } else {
                            $.messager.alert('提示消息', json.message, 'info');
                        }
                    }, 'json');
                }
            });
        }
        function edit(id) {
            App.dialog.show({
                css: 'width:300px;height:300px;',
                title: '修改',
                href: "${contextPath}/security/hdw/battery/edit.htm?id=" + id,
                event: {
                    onClose: function () {
                        reload();
                    },
                    onLoad: function () {
                    }
                }
            });
        }

        function view(id) {
            App.dialog.show({
                css: 'width:650px;height:440px;',
                title: '查看',
                href: "${contextPath}/security/hdw/battery/view.htm?id=" + id
            });
        }
        <#-- 使用记录 old -->
        function usageLog(id) {
            App.dialog.show({
                css: 'width:568px;height:300px;',
                title: '使用记录',
                href: "${contextPath}/security/hdw/battery/usageLog.htm?batteryId=" + id
            });
        }
        <#-- 使用记录 new -->
        function usageLogNew(id) {
            window.location.href = "${contextPath}/security/hdw/exchange_order/second_battery_id.htm?secondBatteryId=" + id;
        }
        <#-- 电池日志 new -->
        function battery_log(id) {
            window.location.href = "${contextPath}/security/hdw/battery_report_log/find_battery_id.htm?batteryId=" + id;
        }
    </script>
    </@app.head>

    <@app.body>

        <@app.container>
            <@app.banner/>

        <div class="main">
            <@app.menu/>

            <div class="content">
                <div class="panel search">
                    <div class="float_right">
                        <button class="btn btn_yellow" onclick="query()">搜索</button>
                    </div>
                    <table cellpadding="0" cellspacing="0" border="0">
                        <tr>
                            <td width="80" align="right">电池序号：</td>
                            <td><input type="text" class="text" id="batteryId"/></td>
                            <td width="80" align="right">外壳编号：</td>
                            <td><input type="text" class="text" id="shellCode"/></td>
                            <td width="80" align="right">厂商：</td>
                            <td>
                                <select name="supplierId" class="easyui-combobox" style="width: 170px; height: 30px;"
                                        editable="false">
                                    <option value="">请选择</option>
                                    <#list supplierList as supplier>
                                        <option value="${supplier.id}">${supplier.supplierName}</option>
                                    </#list>
                                </select>
                            </td>
                            <td width="80" align="right">状态：</td>
                            <td><select name="status" class="easyui-combobox" style="width: 170px; height: 30px;"
                                        editable="false">
                                <option value="">请选择</option>
                                <#list statusList as status>
                                    <option value="${status.getValue()}">${status.getName()}</option>
                                </#list>
                                </select>
                            </td>
                            <#--新增运营商搜索-->
                        <#if Session['SESSION_KEY_USER'].type == Session['USER_TYPE_PLATFORM'].value>
                            <td width="80" align="right">运营商：</td>
                            <td>
                                <input name="agentId" class="easyui-combotree" editable="false"
                                       style="width: 170px; height: 28px;"
                                       data-options="url:'${contextPath}/security/basic/agent/tree.htm?dummy=${'所有'?url}',method:'get',onSelect: function(rec){
                                       var url = '${contextPath}/security/hdw/agency/tree.htm?dummy=${'所有'?url}&agentId='+rec.id;
                                       $('#agency_id').combotree('reload', url);},
                                       onChange:function(){
                                       $('#agency_id').combotree('clear');}"/>
                            </td>
                        </#if>
                        <#--如果是总部或者运营商登录-->
                        <#if Session['SESSION_KEY_USER'].type == Session['USER_TYPE_PLATFORM'].value||Session['SESSION_KEY_USER'].type == Session['USER_TYPE_AGENT'].value>
                            <td width="80" align="right">代理商：</td>
                            <td>
                                <input name="agencyId" class="easyui-combotree" editable="false"
                                       style="width: 170px; height: 28px;" id="agency_id"
                                       data-options="url:'${contextPath}/security/hdw/agency/tree.htm?dummy=${'所有'?url}&agentId=${Session['SESSION_KEY_USER'].agentId}'"/>
                            </td>
                        </#if>
                        </tr>
                    </table>
                </div>
                <div class="panel grid_wrap">
                    <div class="toolbar clearfix">
                        <div class="float_right">
                            <button class="btn btn_red" onclick="abnormalBatteryClick()">异常电池</button>
                        </div>
                        <div class="float_right">
                            <button class="btn btn_red" onclick="faultBatteryClick()">故障电池</button>
                        </div>
                        <div class="float_right">
                            <@app.has_oper oper_code='3_3_5'>
                                <a href="${contextPath}/security/basic/baidu_map/twinkle_location.htm" target="_blank">
                                    <button class="btn btn_blue">分布图</button>
                                </a>
                            </@app.has_oper>
                        </div>
                        <div class="float_right">
                            <@app.has_oper oper_code='3_3_2'>
                                <button class="btn btn_green add" onclick="add()">新建</button>
                            </@app.has_oper>
                        </div>
                        <h3>电池</h3>
                    </div>
                    <div class="grid">
                        <table id="page_table"></table>
                    </div>
                </div>
            </div>
        </div>
        </@app.container>
    </@app.body>
</@app.html>
